//
//  TransferConfirmationView.m
//  Bees
//
//  Created by xiaohan on 2018/12/25.
//  Copyright © 2018 xiaohan. All rights reserved.
//

#import "TransferConfirmationView.h"
#import "LEEAlert.h"

@interface TransferConfirmationView()
@property (nonatomic,strong)TransferModel *info;
@property (nonatomic,strong)UILabel *resultLab1;
@property (nonatomic,strong)UILabel *resultLab2;
@property (nonatomic,strong)UILabel *resultLab3;
@property (nonatomic,strong)UILabel *resultLab4;
@end

@implementation TransferConfirmationView

+ (void)showInfo:(TransferModel*)info sureAction:(ConfirmationSureBlock)sureAction{
        TransferConfirmationView *view = [[TransferConfirmationView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, AdaptedWidth(360)) ];
        view.info = info;
        view.sureBlock  = sureAction;
        view.resultLab1.text = info.from;
        view.resultLab2.text = info.to;
        view.resultLab3.text = info.quantity;
        view.resultLab4.text = info.memo;
        [LEEAlert actionsheet].config
        .LeeItemInsets(UIEdgeInsetsMake(0, 0, 0, 0))
        .LeeMaxWidth(kScreenWidth)
        .LeeAddCustomView(^(LEECustomView *custom) {
            custom.view = view;
            custom.isAutoWidth = YES;
        })
        .LeeActionSheetBottomMargin(-AdaptedWidth(6.5)) // 设置底部距离屏幕的边距为0
        .LeeCornerRadius(AdaptedWidth(13)) // 设置圆角曲率为0
        .LeeShow().LeeCloseComplete(^(){
        });
}
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    UILabel*tipLab = [UILabel new];
    tipLab.textColor = UIColorHex(333333);
    tipLab.font = kBoldFont(16);
    tipLab.text = XLocalized(@"交易确认");
    [self addSubview:tipLab];
    [tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(0);
    }];
    UIButton *closeBtn = [UIButton new];
    [closeBtn setImage:IMAGE_NAMED(@"black_close") forState:UIControlStateNormal];
    [self addSubview:closeBtn];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(tipLab.mas_centerY);
        make.right.mas_equalTo(0);
    }];
    [closeBtn addTapBlock:^(UIButton * _Nonnull btn) {
        [LEEAlert closeWithCompletionBlock:nil];
    }];
    
    UILabel*tipLab1 = [self creatTipLab:@"付款账号"];
    [self addSubview:tipLab1];
    [tipLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.equalTo(tipLab.mas_bottom).offset(AdaptedWidth(35));
    }];
    UIView*line1 = [self creatLine];
    [self addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.equalTo(tipLab1.mas_bottom).offset(AdaptedWidth(23));
        make.height.mas_equalTo(CGFloatFromPixel(1));
    }];
    
    UILabel*tipLab2 = [self creatTipLab:@"收款账号"];
    [self addSubview:tipLab2];
    [tipLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.equalTo(line1.mas_bottom).offset(AdaptedWidth(23));
    }];
    UIView*line2 = [self creatLine];
    [self addSubview:line2];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.equalTo(tipLab2.mas_bottom).offset(AdaptedWidth(23));
        make.height.mas_equalTo(CGFloatFromPixel(1));
    }];
    
    UILabel*tipLab3 = [self creatTipLab:@"转账金额"];
    [self addSubview:tipLab3];
    [tipLab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.equalTo(line2.mas_bottom).offset(AdaptedWidth(23));
    }];
    UIView*line3 = [self creatLine];
    [self addSubview:line3];
    [line3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.equalTo(tipLab3.mas_bottom).offset(AdaptedWidth(23));
        make.height.mas_equalTo(CGFloatFromPixel(1));
    }];
    
    UILabel*tipLab4 = [self creatTipLab:@"备注"];
    [self addSubview:tipLab4];
    [tipLab4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.equalTo(line3.mas_bottom).offset(AdaptedWidth(23));
    }];
  
    XThemeFlatButton *sureBtn = [XThemeFlatButton button];
    [sureBtn setTitle:XLocalized(@"确认支付") forState:UIControlStateNormal];
    [self addSubview:sureBtn];
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(AdaptedWidth(40));
    }];
    
    UIView*line4 = [self creatLine];
    [self addSubview:line4];
    [line4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.equalTo(tipLab4.mas_bottom).offset(AdaptedWidth(23));
        make.height.mas_equalTo(CGFloatFromPixel(1));
        make.bottom.equalTo(sureBtn.mas_top).offset(AdaptedWidth(-23));
    }];
    
    kWeakSelf(self);
    [sureBtn addTapBlock:^(UIButton * _Nonnull btn) {
        [LEEAlert closeWithCompletionBlock:^{
            !weakself.sureBlock?:weakself.sureBlock(weakself.info);
        }];
    }];
    
    self.resultLab1 = [self creatResultLab];
    [self addSubview:self.resultLab1];
    [self.resultLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(tipLab1.mas_centerY);
        make.left.equalTo(tipLab1.mas_right).offset(AdaptedWidth(9));
    }];
    
    self.resultLab2 = [self creatResultLab];
    [self addSubview:self.resultLab2];
    [self.resultLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(tipLab2.mas_centerY);
        make.left.equalTo(tipLab1.mas_right).offset(AdaptedWidth(9));
    }];
    
    self.resultLab3 = [self creatResultLab];
    [self addSubview:self.resultLab3];
    [self.resultLab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(tipLab3.mas_centerY);
        make.left.equalTo(tipLab3.mas_right).offset(AdaptedWidth(9));
    }];
    
    self.resultLab4 = [self creatResultLab];
    self.resultLab4.numberOfLines = 0;
    [self addSubview:self.resultLab4];
    [self.resultLab4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(line3.mas_bottom).offset(AdaptedWidth(5));
        make.left.equalTo(tipLab4.mas_right).offset(AdaptedWidth(9));
        make.right.mas_equalTo(0);
        make.bottom.equalTo(line4.mas_top).offset(AdaptedWidth(-5));
    }];
}
- (UILabel*)creatTipLab:(NSString*)tip
{
    UILabel*tipLab = [UILabel new];
    tipLab.font = kDefaultFont(15);
    tipLab.text = XLocalized(tip);
    tipLab.textColor = UIColorHex(333333);
    return tipLab;
}
- (UIView*)creatLine{
    UIView *line = [UIView new];
    line.backgroundColor = kLineColor;
    return line;
}
- (UILabel*)creatResultLab
{
    UILabel*label = [UILabel new];
    label.font = kDefaultFont(13);
    label.textColor = UIColorHex(#B5B5B5);
    return label;
}
@end


@implementation TransferModel



@end
